<?php
include '../db_params.php';

$fuid=$activity_name=$_POST['fuid'];
$activity_name=$_POST['name'];
$activity_details=$_POST['details'];
$activity_date=$_POST['date'];
$activity_location=$_POST['place'];

$invitations=$_POST['invitations'];
 
mysql_query("INSERT INTO activities (name,details,location,createdby) VALUES ('$activity_name','$activity_details','$activity_location','$fuid');");

$result = @mysql_query("SELECT LAST_INSERT_ID()");

$activity_id=-1;

while($row = mysql_fetch_array($result))
  {
	$activity_id=$row[0];
  }
  
mysql_query("INSERT INTO activity_members (activity_id,uid,type) VALUES ('$activity_id','$fuid','creator')");

//$result = @mysql_query("INSERT INTO activities (name,details,location,createdby) VALUES ('$activity_name','$activity_details','$activity_location','$fuid');");


foreach ($invitations as $i)
{
	//echo $i.',';
	mysql_query("INSERT INTO activity_members (activity_id,uid,type) VALUES ('$activity_id','$i','invited')");
}

mysql_close($con);
echo 'ok';
?>